<?php if(isset($_GET ['id'])){ 
if($id = isset($_GET['id']) ? $_GET['id'] : ""){
   $where = isset($_GET['id']) ? "WHERE id_entreprise=".$_GET['id'] : ""; 
}else{
    $where="";
}
}
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            body{
                background-color: lavender;
            }
            table{
                border :solid black 1px;
                margin :20px;
                background-color: white;
                
            }
            tr{
               border :solid black 1px;
               padding: 10px;
            }
            td{
                border :solid black 1px;
                padding: 10px;
            }
        </style>
    </head>
    <body>
           <?php
        $serveur="localhost"; 
        $user="root"; 
        $password="root";
        $database="carnet_adresses";
        $connexion_serveur = mysqli_connect($serveur, $user, $password,$database);
        
        $sql = "SELECT * FROM contacts";
        $croissant = "SELECT * FROM contacts ORDER BY nom ASC";
        $decroissant = "SELECT * FROM contacts ORDER BY nom DESC";
        $req = mysqli_query($connexion_serveur, $sql);
        $nbre_total = mysqli_num_rows($req);
         ?>
        <h1>Liste des Contacts</h1>
        <div> Nombres de contacts affichés : <?php echo $nbre_total; ?></div><br>
         <form action="" method="post">
        <button type="submit" name="button">croissant</button>
        <button type="submit" name="button2">decroissant</button>
        <button type="submit" name="button3">Tout</button>
        </form>
        <?php
         if(isset($_POST["button"])){
        $envoi_requete = mysqli_query($connexion_serveur, $croissant);
        while($resultats = mysqli_fetch_assoc($envoi_requete)) {
            ?>
            
   <table>
     <tr>
      <td>Numero :</td>
      <td><?php echo $resultats['id']?></td>
     </tr>
     
     <tr>
      <td>Entreprise :</td>
      <td><?php 
                        //REQUETE SQL
                        $sql_ent = "SELECT raison_sociale FROM entreprises WHERE id=".$resultats["id_entreprise"];
                        $req_ent = mysqli_query($connexion_serveur, $sql_ent);
                        $data_ent = mysqli_fetch_assoc($req_ent);
                        
                        echo $data_ent["raison_sociale"];
                        ?></td>
     </tr>
        
        
     <tr>
      <td>Nom</td>
      <td><?php echo $resultats['nom']?></td>
     </tr>
      
     <tr>
     <td>Prenom</td>
      <td><?php echo $resultats['prenom']?></td>
     </tr>
      <tr>
      <td>Telephone</td>
      <td><?php echo $resultats['telephone']?></td>
     </tr>
     <tr>
      <td>Email</td>
      <td><?php echo $resultats['email']?></td>
     </tr>
     <tr>
      <td>Photo</td>
      <td><?php echo $resultats['photo']?></td>
     </tr>
     <tr>
      <td>Observation</td>
      <td><?php echo $resultats['observations']?></td>
     </tr>
   </table>
        
      <?php  }
           
        }elseif(isset($_POST["button2"])){
             //si le bouton
        $envoi_requete = mysqli_query($connexion_serveur, $decroissant);
        while($resultats = mysqli_fetch_assoc($envoi_requete)) {
            
                 ?>
         <table>
     <tr>
      <td>Numero :</td>
      <td><?php echo $resultats['id']?></td>
     </tr>
     <tr>
      <td>Entreprise :</td>
      <td><?php 
                        //REQUETE SQL
                        $sql_ent = "SELECT raison_sociale FROM entreprises WHERE id=".$resultats["id_entreprise"];
                        $req_ent = mysqli_query($connexion_serveur, $sql_ent);
                        $data_ent = mysqli_fetch_assoc($req_ent);
                        
                        echo $data_ent["raison_sociale"];
                        ?></td>
     </tr>
     <tr>
      <td>Nom</td>
      <td><?php echo $resultats['nom']?></td>
     </tr>
     <tr>
     <td>Prenom</td>
      <td><?php echo $resultats['prenom']?></td>
     </tr>
      <tr>
      <td>Telephone</td>
      <td><?php echo $resultats['telephone']?></td>
     </tr>
     <tr>
      <td>Email</td>
      <td><?php echo $resultats['email']?></td>
     </tr>
     <tr>
      <td>Photo</td>
      <td><?php echo $resultats['photo']?></td>
     </tr>
     <tr>
      <td>Observation</td>
      <td><?php echo $resultats['observations']?></td>
     </tr>
   </table>
        
      <?php  }
      }elseif(isset($_POST["button3"])){
             //sinon  normal
        $envoi_requete = mysqli_query($connexion_serveur, $sql);
        while($resultats = mysqli_fetch_assoc($envoi_requete)) {
            
                 ?>
        <table>
     <tr>
      <td>Numero :</td>
      <td><?php echo $resultats['id']?></td>
     </tr>
     <tr>
      <td>Entreprise :</td>
      <td><?php 
                        //REQUETE SQL
                        $sql_ent = "SELECT raison_sociale FROM entreprises WHERE id=".$resultats["id_entreprise"];
                        $req_ent = mysqli_query($connexion_serveur, $sql_ent);
                        $data_ent = mysqli_fetch_assoc($req_ent);
                        
                        echo $data_ent["raison_sociale"];
                        ?></td>
     </tr>
     <tr>
      <td>Nom</td>
      <td><?php echo $resultats['nom']?></td>
     </tr>
     <tr>
     <td>Prenom</td>
      <td><?php echo $resultats['prenom']?></td>
     </tr>
      <tr>
      <td>Telephone</td>
      <td><?php echo $resultats['telephone']?></td>
     </tr>
     <tr>
      <td>Email</td>
      <td><?php echo $resultats['email']?></td>
     </tr>
     <tr>
      <td>Photo</td>
      <td><?php echo $resultats['photo']?></td>
     </tr>
     <tr>
      <td>Observation</td>
      <td><?php echo $resultats['observations']?></td>
     </tr>
   </table>
        <?php  }
        }else{
             //sinon  normal
        $envoi_requete = mysqli_query($connexion_serveur, $sql);
        while($resultats = mysqli_fetch_assoc($envoi_requete)) {
            
                 ?>
          <table>
     <tr>
      <td>Numero :</td>
      <td><?php echo $resultats['id']?></td>
     </tr>
     <tr>
      <td>Entreprise :</td>
      <td><?php 
                        //REQUETE SQL
                        $sql_ent = "SELECT raison_sociale FROM entreprises WHERE id=".$resultats["id_entreprise"];
                        $req_ent = mysqli_query($connexion_serveur, $sql_ent);
                        $data_ent = mysqli_fetch_assoc($req_ent);
                        
                        echo $data_ent["raison_sociale"];
                        ?></td>
     </tr>
     <tr>
      <td>Nom</td>
      <td><?php echo $resultats['nom']?></td>
     </tr>
     <tr>
     <td>Prenom</td>
      <td><?php echo $resultats['prenom']?></td>
     </tr>
      <tr>
      <td>Telephone</td>
      <td><?php echo $resultats['telephone']?></td>
     </tr>
     <tr>
      <td>Email</td>
      <td><?php echo $resultats['email']?></td>
     </tr>
     <tr>
      <td>Photo</td>
      <td><?php echo $resultats['photo']?></td>
     </tr>
     <tr>
      <td>Observation</td>
      <td><?php echo $resultats['observations']?></td>
     </tr>
   </table>
        <?php  }
        }

        ?>
      
        
        
    </body>
</html>
